package com.example.cunion.controller;

import com.example.cunion.common.R;
import com.example.cunion.controller.form.PageFom;
import com.example.cunion.entity.Operation;
import com.example.cunion.service.OperationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/operation")
public class OperationController {

    @Resource
    private OperationService operationService;

    @GetMapping("/getAllOperation")
    public R getAllOperation(@RequestHeader("token") String token){
        ArrayList<HashMap> list = operationService.searchAllOperation();
        return R.ok().put("result", list);
    }

    @PostMapping("/addOperationByMp")
    public R addOperationByMp(@RequestHeader("token") String token, @RequestBody Operation operation) {
        operationService.addOperationByMp(operation);
        return R.ok();
    }

    @GetMapping("/deleteOperationByMp")
    public R deleteOperationByMp(@RequestHeader("token") String token, @RequestParam("operationId") String operationId) {
        operationService.deletedOperationByMp(operationId);
        return R.ok();
    }
    @PostMapping("/updateOperationByMp")
    public R updateOperationByMp(@RequestHeader("token") String token, @RequestBody Operation operation) {
        operationService.updateOperationByMp(operation);
        return R.ok();
    }
    @PostMapping("/searchOperationByMp")
    public R searchOperationByMp(@RequestHeader("token") String token, @RequestBody PageFom form){
        List<Operation> list = operationService.searchOperationByMp(form.getStart(), form.getLength());
        return R.ok().put("result", list);
    }
}
